#ifndef BOARD_H
#define BOARD_H

#include <QWidget>
#include"qizi.h"
#include"Step.h"
#include<QVector>

class Board : public QWidget
{
    Q_OBJECT
public:
    explicit Board(QWidget *parent = nullptr);
    ~Board();
    qizi _s[32];
    int _r;
    int _selectid;
    bool _bRedTurn;//控制轮到谁走
    bool _bSide;
    QVector<Step*> _steps;

    QPoint center(int row,int col);//返回象棋行列对应的像素坐标
    QPoint center(int id);
    bool getRowCol(QPoint pt,int &row,int &col);

    void drawqizi(QPainter& painter,int id);
    void paintEvent(QPaintEvent *);
    void mouseReleaseEvent(QMouseEvent *);
    void drawRightAngle(QPainter &pt, QPoint c);

    bool canMove(int moveid,int row,int col,int killid);
    bool canMoveJIANG(int moveid,int row,int col,int killid);
    bool canMoveSHI(int moveid,int row,int col,int killid);
    bool canMoveXIANG(int moveid,int row,int col,int killid);
    bool canMoveCHE(int moveid,int row,int col,int killid);
    bool canMoveMA(int moveid,int row,int col,int killid);
    bool canMovePAO(int moveid,int row,int col,int killid);
    bool canMoveBING(int moveid,int row,int col,int killid);

    int getqiziCountAtline(int row1,int col1,int row2,int col2);
    bool isBottomSide(int d);
    int getqiziId(int row,int col);
    bool canselect(int id);
    void tryselectqizi(int id);
    bool isDead(int id);
    bool samecolor(int id1,int id2);
    void trymoveqizi(int killid,int row,int col);
    bool red(int id);
    void moveqizi(int moveid,int row,int col);
    void killqizi(int id);
    void reliveqizi(int id);
    void moveqizi(int moveid,int killid,int row,int col);
    void saveStep(int moveid,int killid,int row,int col,QVector<Step*> &steps);
    void back(Step *step);
    void backone();
    virtual void back();

    bool getClickRowCol(QPoint pt, int &row, int &col);
    virtual void click(int id, int row, int col);
    void click(QPoint pt);



    void drawInitPosition(QPainter &p, int row, int col);
    QPoint topLeft(int row, int col);
    QPoint topLeft(int id);
    QRect cell(int row, int col);
    QRect cell(int id);
    void backStep();

signals:

public slots:
    void slotback();
};

#endif // BOARD_H
